package com.xiaohei.crm.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xiaohei.crm.common.result.Result;
import com.xiaohei.crm.dao.Orders;
import com.xiaohei.crm.service.OrdersService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * ClassName: OrdersController
 * Package:
 * Description:
 *
 * @Author:xiaohei
 * @Create 2024/6/24 8:35
 * Version 1.0
 */
@RestController
@RequiredArgsConstructor
@CrossOrigin
public class OrdersController {

    private final OrdersService ordersService;
    /**
     * 分页查询区域信息
     * @return
     */
    @GetMapping("/orders/findByPage")
    public Result<IPage> findByPage(){
        return ordersService.findByPage();
    }

    /**
     * 添加用户
     * @param
     * @return
     */
    @PostMapping("/orders")
    public Result save(@RequestBody Orders orders){
        ordersService.saveOrders(orders);
        return Result.ok();
    }

    /**
     * 修改区域信息
     * @param
     * @return
     */
    @PutMapping("/orders")
    public Result update(@RequestBody Orders orders){
        ordersService.updateOrdersById(orders);
        return Result.ok();
    }

    /**
     * 逻辑删除区域
     * @param
     * @return
     */
    @DeleteMapping("orders/{id}")
    public Result<String> deleteByUsername(@PathVariable("id") String id){
        ordersService.removeByOrdersId(id);
        return Result.ok();
    }

}
